cmake_minimum_required(VERSION 3.16)
#使用VCPKG进行包管理
# 设置CMake在查找依赖时优先使用vcpkg要放在项目命名前
# include(C:/vcpkg/vcpkg-master/scripts/buildsystems/vcpkg.cmake)
# set(CMAKE_TOOLCHAIN_FILE="C:/vcpkg/vcpkg-master/scripts/buildsystems/vcpkg.cmake")


project(apptest VERSION 0.1 LANGUAGES CXX)
 set(CMAKE_AUTOUIC ON)
 set(CMAKE_AUTOMOC ON)
 set(CMAKE_AUTORCC ON)
 set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


find_package(Qt6 REQUIRED COMPONENTS Quick Core Qml Gui)

qt_standard_project_setup(REQUIRES 6.5)

qt_add_executable(apptest
    main.cpp
)

qt_add_qml_module(apptest
    URI apptest
    VERSION 1.0
    QML_FILES
        Main.qml
)

# 添加内部globalData模块
add_library(globalData STATIC
    globalData/globaldata.ixx
    globalData/globaldata.cpp
)
target_link_libraries(globalData PRIVATE Qt${QT_VERSION_MAJOR}::Core
     Qt${QT_VERSION_MAJOR}::Gui
     Qt${QT_VERSION_MAJOR}::Qml
     Qt${QT_VERSION_MAJOR}::Quick)
# 启用SKIP_AUTOMOC选项，避免为模块接口文件生成MOC文件moc 手动生成
#globaldata.ixx -o moc_globaldata.cpp
#并在globaldata.cpp的最后添加 #include "globaldata.moc"
set_source_files_properties(globalData/globaldata.ixx PROPERTIES SKIP_AUTOMOC ON)


add_library(modbusClientThread STATIC
    modbusClientThread/modbusClientThread.ixx
    modbusClientThread/modbusClientThread.cpp
)
target_link_libraries(modbusClientThread PRIVATE Qt${QT_VERSION_MAJOR}::Core
     Qt${QT_VERSION_MAJOR}::Gui
     Qt${QT_VERSION_MAJOR}::Qml
     Qt${QT_VERSION_MAJOR}::Quick)
set_source_files_properties(modbusClientThread/modbusClientThread.ixx PROPERTIES SKIP_AUTOMOC ON)


add_library(opcUaClientThread STATIC
    opcUaClientThread/opcUaClientThread.ixx
    opcUaClientThread/opcUaClientThread.cpp
)
target_link_libraries(opcUaClientThread PRIVATE Qt${QT_VERSION_MAJOR}::Core
     Qt${QT_VERSION_MAJOR}::Gui
     Qt${QT_VERSION_MAJOR}::Qml
     Qt${QT_VERSION_MAJOR}::Quick)
set_source_files_properties(opcUaClientThread/opcUaClientThread.ixx PROPERTIES SKIP_AUTOMOC ON)




# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
set_target_properties(apptest PROPERTIES
#    MACOSX_BUNDLE_GUI_IDENTIFIER com.example.appapptest
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

target_link_libraries(apptest
    PRIVATE Qt6::Quick
    Qt6::Core
    Qt6::Qml
    Qt6::Gui
    globalData
    modbusClientThread
    opcUaClientThread
    XYmodbus
    XYtcpSocket
    XYopcUa
    XYvisionCoreplugin
)
##VCPKG包管理内查找第三方库并链接库
# find_package(libmodbus CONFIG REQUIRED)
#   target_link_libraries(apptest PRIVATE
#       modbus#libmodbus
#   )


# #以下是怎么单独添加第三方库示例
# #OpenCV
# set(OPENCV_DIR "D:/software/iot/Qt6/6.4.0/mingw_64/opencv-4.6.0/build/install/include")
# set(OPENCVLINK_DIR "D:/software/iot/Qt6/6.4.0/mingw_64/opencv-4.6.0/build/install/x64/mingw/lib")
# #如果第三方库在项目文件内
# 指定头文件路径
#include_directories(${CMAKE_SOURCE_DIR}/include)#这里的include是具体文件夹路径
# 指定库文件路径
#link_directories(${CMAKE_SOURCE_DIR}/lib)#这里的lib是具体文件夹路径
# include_directories(${OPENCV_DIR})
# link_directories(${OPENCVLINK_DIR})
#OPENCV
# target_link_libraries(qmlBasePoroject
#     PRIVATE libopencv_calib3d460.dll.a
#)

include(GNUInstallDirs)
install(TARGETS apptest
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
